// 04jyhs/bizAdmin/pointSend/pointSend.js
var co = require("../../../resource/js/common.js")
var ws = require("../../../resource/js/websocket.js")
var _this, _data, _opt
var _pageNum = 1
Page({
   data: {
      reclaimList:[],
      //是否隐藏显示底部提示
      hint: true,
      //frame高度
      frame_h: 1800,
      Biz_ID:"",
   },
   onLoad: function (opt) {
      _this = this
      _data = _this.data
      _data.Biz_ID = opt.Biz_ID
      _opt = opt.Order_ID
      _this.setData({
         frame_h: wx.getSystemInfoSync().windowHeight + 10
      })
      _this.getreclaimList()
   },
   onUnload: function () {
      _pageNum = 1
   },
   onReachBottom: function () {
      _this.getreclaimList()
   },
   //获取回收端人列表
   getreclaimList() {
      wx.showLoading({
         title: '正在加载数据中...',
      })
      co.getShareApi("jyhs/Usermg/get_JYHSB_UserList", {
         Biz_ID: _data.Biz_ID,
         page: _pageNum
      }, function (res) {
         wx.hideLoading()
         if (res.code == 0) {
            var list = _data.reclaimList.concat(res.data)
            _this.setData({
               reclaimList: list
            })
            _pageNum++
         } else {
            _this.setData({
               hint: false
            })
            co.toastAllText(res.msg)
         }
      })
   },
   //指定给那个回收端人员事件
   pointSendPeople(e) {
      var index = e.currentTarget.id
      var Reclaim_User_ID = _data.reclaimList[index].User_ID
      if(_opt){
         co.getJyhsApi("order/Order/appointReclaimUser",{
            Order_ID: _opt,
            Reclaim_User_ID: Reclaim_User_ID
         },function(res){
             if(res.code == 0){
                 wx.navigateTo({
                    url: '/04jyhs/orderAdmin/orderAdminDetail/orderAdminDetail?reload=' + _opt,
                 })
             }
          })
      }else{
         co.getShareApi("jyhs/Admin/appointedBiz", {
            Biz_ID: _data.Biz_ID,
            Reclaim_User_ID: Reclaim_User_ID
         }, function (res) {
            console.log(res)
            if (res.code == 0) {
               co.toastAllText(res.msg)
               _pageNum = 1
               _data.reclaimList = []
               _this.getreclaimList()
               //ws发送
               var msg = {
                  type: "getBizOrder_Notify",
                  to_biz_id: _data.Biz_ID,
                  to_reclaim_id: Reclaim_User_ID
               }
               ws.sendSocketMsg(JSON.stringify(msg), function (res) {
                  console.log("===", res)
               })
            } else {
               co.toastAllText(res.msg)
            }
         })
      }
   },
})